//
//  JAddImageCell.m
//  
//  jhf
//
//  Created by 计海峰 on 2017/6/1.
//  Copyright © 2017年 计海峰. All rights reserved.
//

#import "JAddImageCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import <CooperSDK/CooperSDK.h>

@implementation JAddImageCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    [self addSubview:self.imageV];
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self addSubview:self.deletBT];
    [self.deletBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.equalTo(self);
    }];
}

- (void)setEntity:(JAddImageModel *)entity{
    _entity = entity;
    [entity controlIMG:self.imageV blockBool:nil];
    if (entity.deletBTControl) {
        self.deletBT.hidden = false;
        [entity.deletBTControl controlBT:self.deletBT];
    }else {
        self.deletBT.hidden = true;
    }
//    if (_entity.imageSource) {
//        [_imageview setImage:_entity.imageSource];
//    }else if (_entity.imageName){
//        [_imageview setImage:[UIImage imageNamed:_entity.imageName]];
//    }else if (_entity.imageUrl){
//        if (_entity.imagePlaceholder) {
//            [_imageview sd_setImageWithURL:cp_imageUrl(_entity.imageUrl) placeholderImage:[UIImage imageNamed:_entity.imagePlaceholder]];
//        }else{
//            [_imageview sd_setImageWithURL:cp_imageUrl(_entity.imageUrl)];
//        }
//    }
}

- (void)deletAction:(id)sender {
    if (self.block) {
        self.block(-2, self.entity);
    }
}

// MARK: - lazy
- (UIButton *)deletBT {
    if (!_deletBT) {
        _deletBT = [[UIButton alloc] init];
        [_deletBT addTarget:self action:@selector(deletAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deletBT;
}

- (UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] init];
    }
    return _imageV;
}

@end
